
<template>
  <div>
    <page :asideShow="asideShow">
      <div slot="toolbar">
        <el-form :inline="true" :model="filters" label-position="right">
          <el-form-item label="状态：">
            <el-select
              @change="refreshPageRequest(1)"
              v-model="filters.auditType"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="item in approvalTypeArr"
                :key="item.value"
                :label="item.name"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="名称：">
            <el-input
              placeholder="请输入"
              clearable
              v-model="filters.name"
              @change="refreshPageRequest(1)"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button @click="handleQuery()" type="primary">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- 内容区域 -->
      <div slot="content">
        <el-table
          :header-cell-style="{ background: '#e7eaf0', color: '#606266' }"
          :data="pageResult"
          stripe
          v-loading="loading"
          style="width: 100%"
          element-loading-text="加载中..."
        >
          <el-table-column prop="name" label="名称" align="center"></el-table-column>
          <el-table-column prop="auditType" label="状态" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              <div>
                <span v-if="scope.row.auditType == 0" style="color: #f56c6c">审核不通过</span>
                <span v-if="scope.row.auditType == 1" style="color: #67c23a">审核通过</span>
                <span v-if="scope.row.auditType == 2" style="color: #67c23a">审核中</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="type" label="类型" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              <div>
                <span v-if="scope.row.type == 'place'" style="color: #f56c6c">场所</span>
                <span v-if="scope.row.type == 'reservation'" style="color: #67c23a">活动</span>
                <span v-if="scope.row.type == 'food'" style="color: #67c23a">餐品</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="person" label="申请人" align="center"></el-table-column>
          <el-table-column prop="phone" label="电话" align="center"></el-table-column>
          <el-table-column prop="currentDate" label="预约日期" align="center"></el-table-column>
          <el-table-column prop="timeDate" label="预约时间" align="center"></el-table-column>
          <el-table-column prop="insertTime" label="申请时间" align="center">
            <template slot-scope="scope">
              <span>{{ $format(scope.row.insertTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            header-align="center"
            align="center"
            width="300"
            :label="$t('action.operation')"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.row)"
                v-show="hasPerm('resource:Reservation:remove')"
              >删除</el-button>
              <el-button
                size="mini"
                type="success"
                v-if="scope.row.auditType == 2"
                @click="handleEdit(scope.row)"
                v-show="hasPerm('resource:Reservation:audit')"
              >审核</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 底部区域 -->
      <div slot="footer">
        <el-pagination
          layout="total, prev, pager, next, jumper"
          @current-change="refreshPageRequest"
          :current-page="pageRequest.page"
          :page-size="pageRequest.limit"
          :total="totalSize"
          style="float: right"
        ></el-pagination>
      </div>
    </page>
    <div v-if="addVisible">
      <el-dialog
        class="dialog-container"
        :title="title"
        :visible.sync="addVisible"
        :modal-append-to-body="false"
        :destroy-on-close="true"
        @close="closeEdit"
      >
        <addBusy
          :data="dataForm"
          @handleSave="handleSave"
          @closeEdit="closeEdit"
          @clickCancel="handleCancel"
        ></addBusy>
      </el-dialog>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: true,
      // 弹框
      tableData: [],
      asideShow: false,
      pageResult: [],
      filters: {
        auditType: 2,
      },
      pageRequest: {
        page: 1,
        limit: 10,
      },
      loading: false,
      totalSize: 0,
      addVisible: false,
      editVisible: false,
      dictList: {},
      approvalTypeArr: [
        { value: 0, name: "未通过" },
        { value: 1, name: "已通过" },
        { value: 2, name: "审核中" },
      ],
      dataForm: {},
      title: "新增",
    };
  },
  async mounted() {
    this.dictList = JSON.parse(sessionStorage.getItem("dictData"));
    this.handleQuery();
    this.organizeMix = await this.getOrganizeMix();
  },
  methods: {
    handleSave: function () {
      this.editVisible = false;
      this.addVisible = false;
      this.handleQuery();
    },
    getDetail(row) {
      this.editVisible = true;
      this.dataForm = row;
    },
    editRow(row) {
      this.dataForm = row;
      this.title = "编辑";
      this.addVisible = true;
    },
    addBusiness() {
      this.dataForm = {};
      this.title = "新增";
      this.addVisible = true;
    },
    //删除
    handleDelete(row) {
      let that = this;
      // delete row.person;
      this.$confirm("确认删除选中记录吗？", "提示", {
        type: "warning",
      }).then(() => {
        that.loading = true;
        let param = Object.assign(row, { status: 2 });
        that.updateOne(param);
      });
    },
    // 拼接图片
    getItemPhoto(id) {
      var url = this.global.baseUrlImage + "avatar/" + id;
      return url;
    },
    handleEdit(row) {
      let that = this;
      this.$confirm("是否审核通过？", "提示", {
        confirmButtonText: "通过",
        cancelButtonText: "不通过",
        type: "warning",
      })
        .then(() => {
          that.loading = true;
          let param = Object.assign(row, { auditType: 1 });
          that.updateOne(param);
        })
        .catch(() => {
          that.loading = true;
          let param = Object.assign(row, { auditType: 0 });
          that.updateOne(param);
        });
    },

    updateOne(e) {
      // let param = e;
      let param = {
        auditType: e.auditType,
        _id: e._id,
      };
      this.$api.wxNotic.sys_reservation_audit({ where: param }).then((res) => {
        this.loading = false;
        this.handleQuery();
      });
    },
    // 查询列表
    handleQuery() {
      let param = {
        page: this.pageRequest.page,
        limit: this.pageRequest.limit,
        where: {
          status: 1,
          auditType: this.filters.auditType,
          name: this.filters.name,
          type: "place",
        },
      };
      let params = Object.assign(param);
      let paramJson = JSON.stringify(params);
      this.loading = true;
      this.$api.wxNotic.sys_auditlist(paramJson).then((res) => {
        if (res.code == 0) {
          this.loading = false;
          this.pageResult = res.data;
          this.totalSize = res.count;
          this.pageResult.map((item) => {
            item.person = item.info.person;
            item.currentDate = item.info.currentDate;
            item.phone = item.info.phone;
            item.timeDate = item.info.timeDate;
          });
        } else {
          this.$message({ message: "操作失败, " + res.msg, type: "error" });
        }
      });
    },

    // 翻页
    refreshPageRequest(val) {
      this.pageRequest.page = val;
      this.handleQuery();
    },
  },
};
</script>

<style lang="scss" scoped>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 250px;
}
.mt20 {
  margin-top: 20px;
}
</style>
